package com.dragon.pear.base;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.afollestad.materialdialogs.MaterialDialog;

import butterknife.ButterKnife;

public abstract class BaseDialog {

    private Context context;
    private MaterialDialog materialDialog;
    public View contentView;

    public BaseDialog(Context context) {
        this.context = context;
        MaterialDialog.Builder builder = new MaterialDialog.Builder(context);

        contentView = View.inflate(context, layoutId(), null);
        builder.customView(contentView, false);
        builder.backgroundColor(Color.TRANSPARENT);
        builder.cancelable(isCancelable());
        materialDialog = builder.build();
        ButterKnife.bind(this, contentView);
        initUiAndListener();
    }

    public Context getContext() {
        return context;
    }

    public MaterialDialog getDialog() {
        return materialDialog;
    }


    public abstract boolean isCancelable();

    public void show() {
        if (materialDialog != null) {
            materialDialog.show();
        }
    }

    public void dismiss() {
        if (materialDialog != null) {
            materialDialog.dismiss();
        }
    }

    public abstract int layoutId();

    public void initUiAndListener() {
    }

}
